package flc.ast.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import flc.ast.R;
import flc.ast.activity.FileCompressActivity;
import flc.ast.activity.PdfConvertPicActivity;
import flc.ast.activity.PicConvertPdfActivity;
import flc.ast.databinding.FragmentFileConvertBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.StkPermissionHelper;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link FileConvertFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class FileConvertFragment extends BaseNoModelFragment<FragmentFileConvertBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_file_convert;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.tvPdfConvertPic.setOnClickListener(this);
        mDataBinding.tvPicConvertPdf.setOnClickListener(this);
        mDataBinding.llFileCompress.setOnClickListener(this);
        mDataBinding.llFileDeCompress.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvPdfConvertPic://pdf转图片
                getManagePermission();
                break;
            case R.id.tvPicConvertPdf://图片转PDF
                getPicturePermission();
                break;
            case R.id.llFileCompress://文件压缩
                FileCompressActivity.type = 0;
                startActivity(FileCompressActivity.class);
                break;
            case R.id.llFileDeCompress://文件解压
                FileCompressActivity.type = 1;
                startActivity(FileCompressActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    private void getManagePermission() {
        StkPermissionHelper.reqManageExternalStoragePermission().reqPermissionDesc(getString(R.string.get_manage_permission)).callback(new StkPermissionHelper.ACallback() {
            @Override
            public void onGranted() {
                startActivity(PdfConvertPicActivity.class);
            }
        }).request();
    }

    private void getPicturePermission() {
        StkPermissionHelper.permission(StkPermissionHelper.Permission.ACCESS_IMAGE_VIDEO)
                .reqPermissionDesc(getString(R.string.get_picture_permission))
                .callback(new StkPermissionHelper.ACallback() {
                    @Override
                    public void onGranted() {
                        startActivity(PicConvertPdfActivity.class);
                    }
                }).request();
    }

}